package com.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.julis.R;


/**
 * Created by sq on 2019/5/9.
 * Functions:
 */
public class NewInput extends FrameLayout {
    private View mRootView;
    public static final int NORMAL = 0;
    public static final int SELECT = 1;
    public static final int RIGHT_ARROW = 2;
    public static final int ONLY_SHOW = 3;
    private String mLeftText;
    private String mHint;
    private int mMaxLines;
    private int mMode;
    //    private onEditClickListener mOnEditClickListener;
    private TextView mTextView;
    //    private NoEmojiEditText mEditText;
    private EditText mEditText;
    private int mBgColor;
    //    private AutoLinearLayout mLLRoot;
    private LinearLayout mLLRoot;
    private int mRightGravity;
    private int mMaxWidth;
    private View dividerLine;
    private int mLeftColor;
    private int mEditInputType;
    //    private final View mDividerLine;
    private Context mContext;
    private int mLeftDrawable;
    //    private onEditChangedListener mOnEditChangedListener;
    private int mLeftTvMarginLeft;
    private int mRightHeight;
    private int mLeftDrawablePadding;

    public NewInput(Context context) {
        this(context,null);
    }


    public NewInput(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

    public NewInput(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mRootView = LayoutInflater.from(context).inflate(R.layout.ttttt_layout_input_view, this, true);
        initView();
        initAttrs(context, attrs);
        requestShow();
//        setOrientation(VERTICAL);
//        dividerLine = new View(context);
//        dividerLine.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2));
//        dividerLine.setBackgroundColor(getResources().getColor(R.color.viewcolor));
//        mDividerLine = LayoutInflater.from(context).inflate(R.layout.line_divider, null);


    }

    private void requestShow() {
        mEditText.setHint(mHint);
        if (!TextUtils.isEmpty(mLeftText))
            mTextView.setText(mLeftText);
        else
            mTextView.setVisibility(GONE);
    }

    private void initView() {
//        addView(mRootView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
//        addView(dividerLine);
        mLLRoot = (LinearLayout) mRootView.findViewById(R.id.ll_inputview);
        mTextView = (TextView) mRootView.findViewById(R.id.tv_input);
//        mEditText = (NoEmojiEditText) this.mRootView.findViewById(R.id.et_input);
        mEditText = (EditText) mRootView.findViewById(R.id.et_input);


    }

    /**
     * @return editText设置文字内容
     */
    public void setEditText(String editTextStr) {
        mEditText.setText(editTextStr);
    }

    private void initAttrs(Context context, AttributeSet attrs) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.InputView);
        if (typedArray != null) {
            mLeftText = typedArray.getString(R.styleable.InputView_leftText);
//            mLeftTvMarginLeft = typedArray.getInt(R.styleable.InputView_leftTvMarginLeftMargin, 20);
            mHint = typedArray.getString(R.styleable.InputView_rightHint);
//            mMode = typedArray.getInt(R.styleable.InputView_mode, NORMAL);
//            mMaxLines = typedArray.getInteger(R.styleable.InputView_maxLines, 1);
//            mMaxWidth = typedArray.getDimensionPixelSize(R.styleable.InputView_maxWidth, 80);
//            mBgColor = typedArray.getColor(R.styleable.InputView_inputbackground, R.color.gray_ebebeb);
//            mRightGravity = typedArray.getInt(R.styleable.InputView_rightGravity, 2);
//            mLeftColor = typedArray.getColor(R.styleable.InputView_leftTvColor, R.color.black_333333);
//            mLeftDrawable = typedArray.getResourceId(R.styleable.InputView_leftDrawable, 0);
//            mRightHeight = typedArray.getInteger(R.styleable.InputView_rightHeight, 0);
//            mLeftDrawablePadding = typedArray.getInteger(R.styleable.InputView_leftdrawablePadding, 0);
//            mEditInputType = typedArray.getInt(R.styleable.InputView_editInputType, 0);
//            typedArray.recycle();
        }
    }


}
